function draw() {
	$('#telephone_text').val('');
	$('#drawDlg').dialog({
		modal : true
	}).dialog('open').dialog('setTitle', '抽奖');
}

function doDraw() {
	if ($('#telephone_text').val().length == 0) {
		$.messager.alert('系统提示', '手机号不能为空!');
		return;
	}
	var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
	if (!myreg.test($('#telephone_text').val())) {
		$.messager.alert('系统提示', '手机号不正确!');
		return;
	}
	$.post(getHttpRequestPath("record/doDraw"), {
		telephone : $('#telephone_text').val()
	}, function(response) {
		if (response.toLowerCase() == "fail") {
			$.messager.alert('系统提示', '抽奖失败!');
		} else {
			$.messager.alert('系统提示', response);
			$('#dg').datagrid('reload');
			$('#dgAward').datagrid('reload');
		}
		$('#drawDlg').dialog('close');
	});
}

function recAward(userId, awardName, patchCount, needCount) {
	$('#recAmount_text').numberspinner('setValue', 0);
	$('#userName_text').val(userId);
	$('#awardName_text').val(awardName);
	$('#patchCount_text').val(patchCount);
	$('#needCount_text').val(needCount);
	$('#dlg').dialog({
		modal : true
	}).dialog('open').dialog('setTitle', '兑换奖品');
}
function saveAmount() {
	var amount = $('#recAmount_text').val();
	amount = amount.length > 0 ? new Number(amount) : 0;
	if (amount == 0) {
		$.messager.alert('系统提示', '请输入需要兑换的数量!');
		return;
	}
	var canRec = 0;
	var patchCount = $('#patchCount_text').val();
	patchCount = patchCount.length > 0 ? new Number(patchCount) : 0;
	var needCount = $('#needCount_text').val();
	needCount = needCount.length > 0 ? new Number(needCount) : 0;
	if (patchCount < needCount) {
		$.messager.alert('系统提示', '可兑换数量不足!');
		return;
	} else if (patchCount == needCount) {
		canRec = 1;
	} else {
		canRec = patchCount / needCount;
	}
	if (amount > canRec) {
		$.messager.alert('系统提示', '可兑换数量不足!');
		return;
	}
	$.post(getHttpRequestPath("record/recAward"), {
		userId : $('#userName_text').val(),
		awardName : $('#awardName_text').val(),
		amount : amount
	}, function(response) {
		if (response.toLowerCase() == "success") {
			$.messager.alert('系统提示', '兑换成功!');
			$('#dg').datagrid('reload');
			$('#dgAward').datagrid('reload');
		} else if (response.toLowerCase() == "noenough") {
			$.messager.alert('系统提示', '兑换碎片数不足!');
		} else {
			$.messager.alert('系统提示', '兑换失败!');
		}
		$('#dlg').dialog('close');
	});
}